home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -in_the_mag- / workbench / adf / adflib / adflib.lha / Faq / adf_info.txt < prev   
Text File  |  1999-05-27  |  81KB  |  1,796 lines

  1.   ------------------------------------------------------------------------
  2.  
  3. The .ADF (Amiga Disk File) format FAQ
  4.  
  5. Laurent Clévy, laurent.clevy@alcatel.fr
  6.  
  7. v1.07, 27. May 1999
  8.   ------------------------------------------------------------------------
  9. This document describes the .ADF file format. An Amiga Disk File is a sector
  10. per sector dump of an Amiga formatted disk. The intent is to explain in
  11. detail how the Amiga stores files and directories on floppy and hard disks.
  12. A set of C routines (ADFlib) will be supplied to manage the ADF format.
  13.   ------------------------------------------------------------------------
  14.  
  15. 0. Changes
  16.  
  17. 1. Introduction
  18.  
  19.    * 1.1 Disclaimer and Copyright
  20.    * 1.2 Feedback, updates
  21.    * 1.3 Conventions
  22.    * 1.4 Acknowledgements
  23.  
  24. 2. How bytes are physically read from and written to a disk ?
  25.  
  26.    * 2.1 What is MFM encoding/decoding ?
  27.    * 2.2 What is the MFM track format ?
  28.    * 2.3 What is the MFM sector format ?
  29.    * 2.4 How to decode MFM data ?
  30.  
  31. 3. What is the Amiga floppy disk geometry ?
  32.  
  33. 4. What is the logical organisation of an Amiga volume ?
  34.  
  35.    * 4.1 What is a Bootblock ?
  36.    * 4.2 What is a Rootblock ?
  37.         o 4.2.1 How to find the first sector of an entry ?
  38.         o 4.2.2 How to list directory entries ?
  39.         o 4.2.3 How to compute the checksum ?
  40.    * 4.3 How are the free and used block lists managed ?
  41.    * 4.4 How are files stored ?
  42.    * 4.5 How are directories stored ?
  43.    * 4.6 How are links implemented in AmigaDOS ?
  44.         o 4.6.1 Hard links
  45.         o 4.6.2 Soft links
  46.    * 4.7 How are the blocks associated with the dircache mode ?
  47.  
  48. 5. How does a blank disk look like ?
  49.  
  50.    * 5.1 A minimal blank floppy disk
  51.    * 5.2 A 'Bootable' floppy disk
  52.    * 5.3 A directory cache mode floppy disk
  53.    * 5.4 International mode
  54.  
  55. 6. The structure of a hard disks ?
  56.  
  57.    * 6.1 What is the Rigid Disk Block ?
  58.    * 6.2 How are bad blocks managed ?
  59.    * 6.3 How are partitions stored ?
  60.    * 6.4 What are FSHD blocks ?
  61.    * 6.5 What are LSEG blocks ?
  62.  
  63. 7. The Hard file : a big floppy dump file
  64.  
  65. 8. Advanced information
  66.  
  67. 9. References and links
  68.  
  69. 10. C Routines : the ADF Library
  70.  
  71. 11. Other Amiga file systems
  72.  
  73.   ------------------------------------------------------------------------
  74.  
  75. 0. Changes
  76.  
  77. Since version 1.06 (2. May 1999), by Heiko Rath (hr@brewhr.swb.de) :
  78.  
  79.    * [chg] Minor spelling corrections
  80.    * [chg] Blocksizes other than 512 bytes documented
  81.    * [chg] DosEnvVector extended
  82.    * [add] link to the Amiga Floppy Reader project
  83.  
  84. Since version 1.04 (16. January 1999) :
  85.  
  86.    * [chg] Corrections suggested by Hans-Joachim Widmaier (Linux affs
  87.      maintainer)
  88.    * [add] The WinUAE hardfile format section is starting
  89.  
  90. Since version 0.9 (28. May 1997) :
  91.  
  92.    * [add] HTML version with figures
  93.    * [add] Hard disk section added
  94.    * [chg] Correction about DIRC and INTL modes (section 4.1)
  95.    * [add] The whole rewritten ADF library is released (0.7.8) and used
  96.      within the ADFOpus project
  97.      (http://www.chromerhino.demon.co.uk/adfopus/)
  98.    * [chg] The bitmap checksum algorithm is the same as the rootblock
  99.      algorithm
  100.    * [add] Allowed/forbidden characters in volume and file names, 4GB limit
  101.    * [add] how to rename an entry
  102.  
  103.   ------------------------------------------------------------------------
  104.  
  105. 1. Introduction
  106.  
  107. In this document, we will describe how the AmigaDOS is (was?) managing
  108. storage media, from the magnetic layer to the files and directories layer.
  109.  
  110. With physical layer, I'm talking about the way bytes are physically stored
  111. on a magnetic surface, with the RLL or MFM encoding.
  112. The next layer, according to the 'most physical' to 'most conceptual' order,
  113. is the partitions layer : this is how the AmigaDOS is managing media with
  114. more then one partition, like Zip disks or hard disks.
  115. The next and last layer is the volume layer : where the files and
  116. directories are stored.
  117.  
  118. The physical layer is described in the 2nd chapter,
  119. The volume layer is the biggest part of the document (4th and 5th chapters),
  120. since it's the most interesting,
  121. The partitions layer is explained in the 6th chapter.
  122.  
  123. Let's continue with more conventional things in an introduction.
  124.  
  125.                            -----------------------
  126.  
  127. 1.1 Disclaimer and copyright
  128.  
  129. This document is Copyright (C) 1997-1998 by Laurent Clévy, but may be freely
  130. distributed, provided the author name and addresses are included and no
  131. money is charged for this document.
  132.  
  133. This document is provided "as is". No warranties are made as to its
  134. correctness.
  135.  
  136. Amiga and AmigaDOS are registered Trademarks of Gateway 2000.
  137. Macintosh is a registered Trademark of Apple.
  138.  
  139.                            -----------------------
  140.  
  141. 1.2 Feedback, updates
  142.  
  143. If you find any mistakes in this document, have any comments about its
  144. content, feel free to send me an e-mail.
  145. Corrections are very welcome.
  146.  
  147. You can find new versions of this document at :
  148.  
  149.    * The ADFlib page (http://come.to/adflib or
  150.      http://perso.club-internet.fr/lclevy/adflib/)
  151.    * Aminet, in the ADFlib archive file :
  152.         o ( ftp://fr.aminet.net/pub/aminet/disk/misc/ADFlib.tgz)
  153.         o ( ftp://uk.aminet.net/pub/aminet/disk/misc/ADFlib.tgz)
  154.    * Aminet, in a separate file 'ADFfaq.tgz':
  155.         o ( ftp://fr.aminet.net/pub/aminet/docs/misc/ADFfaq.tgz)
  156.         o ( ftp://uk.aminet.net/pub/aminet/docs/misc/ADFfaq.tgz)
  157.  
  158.                            -----------------------
  159.  
  160. 1.3 Conventions
  161.  
  162. In this document, hexadecimal values use the C syntax : for example 0x0c is
  163. the decimal value 12.
  164.  
  165. Byte ordering
  166.  
  167. Since the Amiga is a 680x0 based computer, integers that require more than
  168. one byte are stored on disk in 'Motorola order' : the most significant byte
  169. comes first, then the less significant bytes in descending order of
  170. significance (MSB LSB for two-byte integers, B3 B2 B1 B0 for four-byte
  171. integers). This is usually called big endian byte ordering.
  172. The Intel based PCs are using the little endian byte ordering.
  173.  
  174. Vocabulary
  175.  
  176. A 'word' or 'short' is a 2-byte (16 bits) integer, a 'long' a 4-byte (32
  177. bits) integer. Values are unsigned unless otherwise noted.
  178.  
  179. A 'block' in this document will be 512 consecutive bytes on disk, unless
  180. noted otherwise, the variable 'BSIZE' will denote the blocksize.
  181. The word 'sector' and 'block' will be used as synonyms here, even if
  182. 'sector' is usually related to the physical side, and the 'block' to the
  183. logical side. This is because the AmigaDOS can only handle one sector per
  184. block. Some other Unix filesystems can have more then one sector per block.
  185.  
  186. A block pointer is the number of this block on the disk. The first one is
  187. the #0 block.
  188. There are 'logical' and 'physical' block pointers. 'Logical' ones are
  189. related to the start of one volume, 'physical' one are related to the start
  190. of a physical media. If a volume starts at the #0 physical sector, a
  191. physical pointer and a logical pointer is the same thing, like with
  192. floppies.
  193.  
  194. A simple definition of 'Hashing' could be : "a method to access tables :
  195. given a number or a string, a hash function returns an index into an array".
  196. This definition is correct for this document, but there is a lot of other
  197. hashing methods, that might be far more complex.
  198.  
  199. Linked lists are cell-oriented data structures. Each cell contains a pointer
  200. to the next or previous cell or both, the last cell pointer is null.
  201.  
  202. C example :
  203.  
  204. struct lcell {
  205.         char name[10];
  206.         /* contains next cell adress, or NULL if this cell is the last */
  207.         struct lcell *next_cell;
  208.         };
  209.  
  210. Block names begin with a capital (Rootblock). Field names are noted between
  211. quotes ('field_name').
  212.  
  213. All formats are described as tables, one row per field. Here is an example
  214. with the beginning of the well known GIF format :
  215.  
  216. offset  type   length  name          comments
  217. ----------------------------------------------------------
  218. 0       char    3      signature     'GIF'
  219. 3       char    3      version       '87a' or '89a'
  220. 6       short   1      screen width  (little endian)
  221. 8       short   1      screen height (little endian)
  222.  
  223. The .ADF format is the format created and used by the -incredible- UNIX
  224. Amiga Emulator (UAE), written by Berndt Schmitt. The home page is here :
  225. http://www.freiburg.linux.de/~uae/
  226.  
  227. The .ADF files can be created with the program transdisk.
  228.  
  229.                            -----------------------
  230.  
  231. 1.4 Acknowledgements
  232.  
  233.    * Hans-Joachim Widmaier for the -detailed- review and suggestions,
  234.    * Dan Sutherland (dan@chromerhino.demon.co.uk) for the suggestions and
  235.      ideas,
  236.    * Jean Yves Peterschmitt (jypeter@lmce.saclay.cea.fr) for the review,
  237.    * Thomas Kessler (tkessler@ra.abo.fi) for the bootcode flag note.
  238.    * Heiko Rath (hr@brewhr.swb.de) for some modifications.
  239.  
  240. 2. How are bytes physically read from / written to a disk ?
  241.  
  242. The following part deals with the way the Amiga disk controller accesses the
  243. magnetic medium. If you only want to understand the .ADF format, you don't
  244. need to read this part.
  245.  
  246. Information is written on disk with magnetic fields. Magnetic fields can be
  247. made 'on' or 'off'. But the read/write heads are not capable of detecting
  248. directly if a field is on or off. An encoding is used to store memory bits
  249. on the medium. The CHANGE of fields polarisation will indicate if the bit is
  250. 1 or 0. For Amiga floppy disks (and PC floppies), the encoding scheme is MFM
  251. (Modified frequency modulation).
  252.  
  253. Notes on the Amiga floppy disk controller :
  254.  
  255. The Amiga floppy disk controller (FDC) which is called 'Paula' is very
  256. flexible. It is capable of reading/writting Amiga/PC/Macintosh floppy disks.
  257.  
  258. Paula can read a variable number of bytes from disk, the PC FDC can't. The
  259. PC FDC uses the index hole to find the beginning of a track, Paula uses a
  260. synchronization word. The Macintosh uses GCR encoding instead of MFM.
  261. In fact, Paula is simpler than the PC FDC because it does not perform
  262. automatically the decoding just after the read operation, and the encoding
  263. just before the write operation : it must be done by software. The MFM
  264. decoding/encoding is done by hardware with the PC FDC, the Amiga can do GCR
  265. or MFM decoding/encoding because it's done with the CPU.
  266.  
  267. Classic PC FDCs can't read Amiga floppy disks even if they are MFM encoded
  268. on a 3.5 inch floppy, because they can not find the beginning of a track.
  269. This is why the .ADF format has been created.
  270.  
  271. However, a custom FDC available on PC machines is capable of reading/writing
  272. Amiga, PC, Macintosh, Atari and C64 floppies !!! This is CatWeasel :
  273. http://catweasel.vme.de/index.html and
  274. http://www.jschoenfeld.com/eindex.html
  275.  
  276. There's also the Amiga Floppy Reader Project at http://metamonkt.com/afr/ a
  277. project describing a small piece of hardware to connect to the parallel port
  278. of a standard PC, enabling it to read Amiga disks.
  279.  
  280. Paula parametrization for Amiga disks :
  281.  
  282.    * MFM encoding
  283.    * Precompensation time : 0 nanoseconds
  284.    * Controller clock rate : 2 microseconds per bit cell
  285.    * Synchronization value : 0x4489
  286.  
  287. Paula is able to put the read/write heads on a cylinder, and is able to read
  288. with the lower or upper side head. A track of 0x1900 words is usually read.
  289.  
  290.                            -----------------------
  291.  
  292. 2.1 What is MFM encoding/decoding ?
  293.  
  294. The MFM decoding is made by the Amiga CPU, not by Paula. This allows custom
  295. encoding, to protect floppies against copying for example.
  296.  
  297. Here follows the MFM encoding scheme :
  298.  
  299.     user's data bit      MFM coded bits
  300.     ---------------      --------------
  301.         1                   01
  302.         0                   10 if following a 0 data bit
  303.         0                   00 if following a 1 data bit
  304.  
  305. User data long words are split in two parts, a part with even bits part
  306. first, followed by a part with odd bits. Once encoded, the amount of data
  307. stored doubles.
  308. The MFM decoding will transform magnetic fields into computer usuable bits.
  309.  
  310. The encoding process will take one long (user's data), and produces two
  311. longs (MFM coded longs): one for the even bits of the user long, a second
  312. for the odd bits of the user long.
  313. Vice versa, the decoding process will take the half of two MFM longs to
  314. produce one user's long.
  315.  
  316.                            -----------------------
  317.  
  318. 2.2 What is the MFM track format ?
  319.  
  320. Paula will search two synchronization words, and then read 0x1900 words of
  321. data. We will call those 0x1900 words a 'MFM track'.
  322. There are 80 cylinders on a Amiga floppy disk. Each cylinder has 2 MFM
  323. tracks, 1 on each side of the disk.
  324.  
  325. Double density (DD) disks have 11 sectors per MFM track, High density (HD)
  326. disks have 22 sectors.
  327.  
  328. So a MFM track consists of 11/22 MFM encoded sectors, plus inter-track-gap.
  329. Note that sectors are not written from #0 to #10/21, you must use the 'info'
  330. field to restore the correct order when you read the tracks. Each MFM track
  331. begins with the first sector, and ends with the end of the last sector.
  332. Each sector starts with 2 synchronization words. The synchronization value
  333. is 0x4489.
  334.  
  335.                            -----------------------
  336.  
  337. 2.3 What is the MFM sector format ?
  338.  
  339. There are brut data and encoded data.
  340. Brut data (also called MFM data) doesn't need to be decoded, this is the
  341. synchronization data, the header checksum and data checksum.
  342.  
  343. The encoded parts are 'header' and 'data'.
  344.  
  345. Here it comes :
  346.  
  347. 00/0x00 word    2       MFM value 0xAAAA AAAA (used for timing ?)
  348.  
  349.         SYNCHRONIZATION
  350. 04/0x04 word    1       MFM value 0x4489
  351. 06/0x06 word    1       MFM value 0x4489
  352.  
  353.         HEADER
  354. 08/0x08 long    1       info (even bits)
  355. 12/0x0c long    1       info (odd bits)
  356.                         decoded long is : 0xff TT SS SG
  357.                                 TT = track number ( 3 means cylinder 1, head 1)
  358.                                 SS = sector number ( 0 upto 10/21 )
  359.                                         sectors are not ordered !!!
  360.                                 SG = number of sectors before gap (including
  361.                                         current one)
  362.                         Example for cylinder 0, head 1 of a DD disk :
  363.                                 0xff010009
  364.                                 0xff010108
  365.                                 0xff010207
  366.                                 0xff010306
  367.                                 0xff010405
  368.                                 0xff010504
  369.                                 0xff010603
  370.                                 0xff010702
  371.                                 0xff010801
  372.                                         -- inter-sector-gap here !
  373.                                 0xff01090b (0xb means -1 ?)
  374.                                 0xff010a0a (0xa means -2 ?)
  375.  
  376. 16/0x10 long    4       sector label (even)
  377. 32/0x20 long    4       sector label (odd)
  378.                         decoded value seems to be always 0
  379.         END OF HEADER
  380.  
  381. 48/0x30 long    1       header checksum (even)
  382. 52/0x34 long    1       header checksum (odd)
  383.                         (computed on mfm longs,
  384.                         longs between offsets 8 and 44
  385.                         == 2*(1+4) longs)
  386.  
  387. 56/0x38 long    1       data checksum (even)
  388. 60/0x3c long    1       data checksum (odd)
  389.                         (from 64 to 1088 == 2*512 longs)
  390.  
  391.         DATA
  392. 64/0x40 long    512     coded data (even)
  393. 576/0x240 long  512     coded data (odd)
  394. 1088/0x440
  395.         END OF DATA
  396.  
  397.                            -----------------------
  398.  
  399. 2.4 How to decode MFM data ?
  400.  
  401. C algorithm :
  402.  
  403. #define MASK 0x55555555 /* 01010101 ... 01010101 */
  404. unsigned long *p1;      /* MFM coded data buffer (size == 2*data_size) */
  405. unsigned long *q;       /* decoded data buffer (size == data_size) */
  406. unsigned long a,b;
  407. unsigned long chksum;
  408. int data_size;          /* size in long, 1 for header's info, 4 for header's sector label */
  409. int count;
  410.  
  411. chksum=0L;
  412. /* the decoding is made here long by long : with data_size/4 iterations */
  413. for (count=0; count<data_size/4; count++) {
  414.         a = *p1;                /* longs with even bits */
  415.         b = *(p1+data_size);    /* longs with odd bits : located 'data_size' bytes farther */
  416.         chksum^=a;              /* eor */
  417.         chksum^=b;
  418.         /*
  419.          * MFM decoding, explained on one byte here (x and y will produce t) :
  420.          * the MFM bytes 'abcdefgh' == x and 'ijklmnop' == y will become
  421.          * y & 0x55U = '0j0l0n0p'
  422.          * ( x & 0x55U) << 1 = 'b0d0f0h0'
  423.          * '0j0l0n0p' | 'b0d0f0h0' = 'bjdlfnhp' == t
  424.          */
  425.         /* on one long here : */
  426.         *q = ( b & MASK ) | ( ( a & MASK ) << 1 );
  427.         p1++;    /* next 'even bits' long and 'odd bits' long  */
  428.         q++;     /* next location of the future decoded long */
  429.         }
  430. chksum&=MASK;   /* must be 0 after decoding */
  431.  
  432. For example, to decode the DATA field of a MFM sector :
  433.  
  434.    * data_size is equal to 512,
  435.    * p1 points to 64 bytes after the beginning of the MFM sector,
  436.    * q points to a 512 unsigned bytes array.
  437.  
  438.   ------------------------------------------------------------------------
  439.  
  440. 3. What is the Amiga floppy disk geometry ?
  441.  
  442. After MFM decoding, you have usuable 'sectors' or 'blocks' into memory.
  443.  
  444. Here we remind the disk geometries for Double Density disks (DD) and High
  445. Density disks (HD) :
  446.  
  447.                 bytes/sector    sector/track    track/cyl       cyl/disk
  448. ------------------------------------------------------------------------
  449. DD disks        512             11              2               80
  450. HD disks        512             22              2               80
  451.  
  452. The relations between sectors, sides and cylinders are for a DD disk :
  453.  
  454. Block   sector  side    cylinder
  455. --------------------------------
  456. 0       0       0       0
  457. 1       1       0       0
  458. 2       2       0       0
  459. ...
  460. 10      10      0       0
  461. 11      0       1       0
  462. ...
  463. 21      10      1       0
  464. 22      0       0       1
  465. ..
  466. 1759    10      1       79
  467.  
  468. Order = increasing sectors, then increasing sides, then increasing
  469. cylinders.
  470.  
  471. A DD disk has 11*2*80=1760 (0 to 1759) blocks, a HD disk has 22*2*80=3520
  472. blocks.
  473.  
  474. The length of .ADF files for a DD disk is therefore 512*11*2*80 = 901120
  475. bytes.
  476.  
  477. Those 'raw' blocks, 512 consecutive bytes, store different 'logical' blocks
  478. to manage files and directories.
  479.  
  480. The classic Amiga filesystem has a internal command with one 32 bits wide
  481. offset parameter (unsigned). It tells where to start the read/write
  482. operation. The biggest size for an Amiga disk is therefore 2^32 = 4 GB.
  483. Anyway, there exists a 3rd party patch which changes the 32 bits limit to 64
  484. bits (on Aminet, disk/misc/ffstd64.lha).
  485.  
  486.   ------------------------------------------------------------------------
  487.  
  488. 4. What is the logical organisation of an Amiga volume ?
  489.  
  490. A volume is a floppy disk or a hard disk partition.
  491.  
  492. The first file system for the Amiga was embedded in the version 1.2 of
  493. AmigaDOS.
  494. With version 2.xx of AmigaDOS the Fast File System (FFS) was introduced, an
  495. improved version of the 1.2, also called old file system (OFS).
  496. The version 3.0 of AmigaDOS added an international characters mode (INTL)
  497. and a directory cache mode (DIRC).
  498.  
  499. Links are only supported under FFS.
  500.  
  501. The start of a floppy volume contains space for sectors which may contain
  502. boot code.
  503. The middle of the volume contains information about the root (upper most)
  504. directory contents and information about free and used blocks.
  505. Other blocks are of course used to store files and directories.
  506.  
  507. The file length, the directory tree depth, the number of entries per
  508. directory are only limited by disk size. (Actually the maximum filesize is
  509. limited to 4 Gbyte sizeof(ulong) which should normally be more than
  510. sufficient).
  511.  
  512. Let's introduce the logical structures used by the Amiga file system in a
  513. table (for floppies) :
  514.  
  515. Object          Related logical blocks
  516. ------------+----------------------------------------------------------------
  517. Volume          Rootblock, Bitmap block
  518. File            File Header block, Extension block, Data block, Link block
  519. Directory       Rootblock, Directory block, Directory Cache block, Link block
  520.  
  521. The main data types are a trees and linked lists.
  522.  
  523.                            -----------------------
  524.  
  525. 4.1 What is a Bootblock ?
  526.  
  527. Prior to Kickstart 2.0 the bootblock was hardcoded to consist of the first
  528. two sectors of the floppy disks (sector #0 and #1). As of Kick 2.0, booting
  529. via the boot-block could be done with any device driver and the number of
  530. blocks could be changed independantly of the number of reserved blocks by
  531. using BOOTBLOCKS in the DOS environment vector (DosEnvVec).
  532.  
  533. * BootBlock
  534. -------------------------------------------------------------------------------
  535. offset  size    number  name            meaning
  536. -------------------------------------------------------------------------------
  537. 0/0x00  char    4       DiskType        'D''O''S' + flags
  538.                                         flags = 3 least signifiant bits
  539.                                                set         clr
  540.                                           0    FFS         OFS
  541.                                           1    INTL ONLY   NO INTL ONLY
  542.                                           2    DIRC&INTL   NO DIRC&INTL
  543. 4/0x04  ulong   1       Chksum          special block checksum
  544. 8/0x08  ulong   1       Rootblock       Value is 880 for DD and HD
  545. 12/0x0c char    *       Bootblock code  (see 5.2 'Bootable disk' for more info)
  546.                                         The size for a floppy disk is 1012,
  547.                                         for a harddisk it is
  548.                                         (DosEnvVec->Bootblocks * BSIZE) - 12
  549. -------------------------------------------------------------------------------
  550.  
  551. The DiskType flag informs of the disk format.
  552.  
  553.    * OFS = Old/Original File System, the first one. (AmigaDOS 1.2)
  554.    * FFS = Fast File System (AmigaDOS 2.04)
  555.    * INTL = International characters Mode (see section 5.4).
  556.    * DIRC = stands for Directory Cache Mode. This mode speeds up directory
  557.      listing, but uses more disk space (see section 4.7).
  558.  
  559. The Old filesystem may have the international and dircache mode enabled. If
  560. the international mode is enabled, the bit #1 is set. If the dircache is
  561. enabled, its flag is set (bit #2), and the international mode is also
  562. enabled, but the related flag (bit #1) will stay cleared. The correct values
  563. for flag are therefore : 0 (OFS), 1 (FFS), 2 (OFS/INTL), 3 (FFS/INTL), 4
  564. (OFS/DIRC&INTL), 5 (FFS/DIRC&INTL).
  565.  
  566. There are few differences between the two file systems :
  567.  
  568.    * OFS Datablock stores BSIZE-24 bytes (i.e. normally 488 bytes at most
  569.      frequently used BSIZE of 512 bytes), FFS stores BSIZE bytes.
  570.    * FFS supports directory caching, links and international mode,
  571.    * the FFS is faster than OFS.
  572.  
  573. If the Bootblock starts with the three characters 'PFS', another filesystem
  574. is used in place of AmigaDOS : the Professional File System.
  575.  
  576. If the checksum and the DiskType are correct, the system will execute the
  577. bootblock code, at boot time, of course :-).
  578.  
  579. The Bootblock code is optional, see 5.2 section.
  580.  
  581. The Bootblock checksum algorithm follows :
  582.  
  583. * in 68000 assembler :
  584.  
  585.         lea     bootbuffer,a0
  586.         move.l  a0,a1
  587.         clr.l   4(a1)                   ;clear the checksum
  588.         move.w  #(BOOTBLOCKSIZE/4)-1,d1 ;for floppy disks = 1024
  589.                                         ;for hd = (DosEnvVec->Bootblocks * BSIZE)
  590.         moveq   #0,d0
  591. lpchk:  add.l   (a0)+,d0                ;accumulation
  592.         bcc.s   jump                    ;if carry set, add 1 to checksum
  593.         add.l   #1,d0
  594. jump:   dbf     d1,lpchk                ;next long word
  595.  
  596.         not.l   d0
  597.         move.l  d0,4(a1)                ;new checksum
  598.  
  599. * in C :
  600.  
  601. #include<limits.h>
  602. #define Short(p) ((p)[0]<<8 | (p)[1])
  603. #define Long(p) (Short(p)<<16 | Short(p+2))
  604.  
  605. unsigned long newsum,d;
  606. unsigned char buf[BOOTBLOCKSIZE];       /* contains bootblock */
  607.                                         /* for floppy disks = 1024,
  608.                                          * for hd = (DosEnvVec->Bootblocks * BSIZE) */
  609. int i;
  610.  
  611. memset(buf+4,0,4);                      /* clear old checksum */
  612. newsum=0L;
  613. for(i=0; i<BOOTBLOCKSIZE/4; i++) {
  614.         d=Long(buf+i*4);
  615.         if ( (ULONG_MAX-newsum) < d )   /* overflow */
  616.                 newsum++;
  617.         newsum+=d;
  618.         }
  619.  
  620. newsum=~newsum;         /* not */
  621.  
  622.                            -----------------------
  623.  
  624. 4.2 What is a Rootblock ?
  625.  
  626. The Rootblock is located at the physical middle of the media : block number
  627. 880 for DD disks, block 1760 for HDs. The exact calculation where it is
  628. stored is as follows:
  629.  
  630. numCyls = highCyl - lowCyl + 1
  631.  
  632. highKey = numCyls * numSurfaces * numBlocksPerTrack - 1
  633.  
  634. rootKey = INT (numReserved + highKey) / 2
  635.  
  636. The Rootblock contains information about the disk : its name, its formatting
  637. date, etc ...
  638.  
  639. It also contains information to access the files/directories/links located
  640. at the uppermost (root) directory.
  641.  
  642. * Root block (BSIZE bytes) sector 880 for a DD disk, 1760 for a HD disk
  643. ------------------------------------------------------------------------------------------------
  644.         0/ 0x00 ulong   1       type            block primary type = T_HEADER (value 2)
  645.         4/ 0x04 ulong   1       header_key      unused in rootblock (value 0)
  646.                 ulong   1       high_seq        unused (value 0)
  647.        12/ 0x0c ulong   1       ht_size         Hash table size in long (= BSIZE/4 - 56)
  648.                                                 For floppy disk value 0x48
  649.        16/ 0x10 ulong   1       first_data      unused (value 0)
  650.        20/ 0x14 ulong   1       chksum          Rootblock checksum
  651.        24/ 0x18 ulong   *       ht[]            hash table (entry block number)
  652.                                                 * = (BSIZE/4) - 56
  653.                                                 for floppy disk: size= 72 longwords
  654. BSIZE-200/-0xc8 ulong   1       bm_flag         bitmap flag, -1 means VALID
  655. BSIZE-196/-0xc4 ulong   25      bm_pages[]      bitmap blocks pointers (first at 0)
  656. BSIZE- 96/-0x60 ulong   1       bm_ext          first bitmap extension block
  657.                                                 (Hard disks only)
  658. BSIZE- 92/-0x5c ulong   1       r_days          last root alteration date : days since 1 jan 78
  659. BSIZE- 88/-0x58 ulong   1       r_mins          minutes past midnight
  660. BSIZE- 84/-0x54 ulong   1       r_ticks         ticks (1/50 sec) past last minute
  661. BSIZE- 80/-0x50 char    1       name_len        volume name length
  662. BSIZE- 79/-0x4f char    30      diskname[]      volume name
  663. BSIZE- 49/-0x31 char    1       UNUSED          set to 0
  664. BSIZE- 48/-0x30 ulong   2       UNUSED          set to 0
  665. BSIZE- 40/-0x28 ulong   1       v_days          last disk alteration date : days since 1 jan 78
  666. BSIZE- 36/-0x24 ulong   1       v_mins          minutes past midnight
  667. BSIZE- 32/-0x20 ulong   1       v_ticks         ticks (1/50 sec) past last minute
  668. BSIZE- 28/-0x1c ulong   1       c_days          filesystem creation date
  669. BSIZE- 24/-0x18 ulong   1       c_mins
  670. BSIZE- 20/-0x14 ulong   1       c_ticks
  671.                 ulong   1       next_hash       unused (value = 0)
  672.                 ulong   1       parent_dir      unused (value = 0)
  673. BSIZE-  8/-0x08 ulong   1       extension       FFS: first directory cache block,
  674.                                                 0 otherwise
  675. BSIZE-  4/-0x04 ulong   1       sec_type        block secondary type = ST_ROOT
  676.                                                 (value 1)
  677. ------------------------------------------------------------------------------------------------
  678.  
  679. The '/' and ':' characters are forbidden in the volume name, but
  680. *!@#$%|^+&_()=\-[]{}';",<>.? and international like âè are allowed.
  681.  
  682. The date fields in the root block (and other blocks) are structured in the
  683. form of DAYS, MINS and TICKS. The DAYS field contains the number of days
  684. since January 1. 1978. MINS is the number of minutes that have passed since
  685. midnight and TICKS are expressed in 1/50s of a second. A day value of zero
  686. is considered illegal by most programs.
  687.  
  688. The r_date / r_min / r_ticks fields are updated to the last recent change of
  689. the root directory of this volume.
  690.  
  691. The v_date / v_min / v_ticks fields are updated whenever any change was made
  692. to this volume, not just the root directory.
  693.  
  694. The c_date / c_min / c_ticks fields contain the date and time when this
  695. volume was initialized (i.e. formatted) and is not changed during its
  696. lifetime.
  697.  
  698. Some date constraints : 0 <= Mins < 60*24, 0 <= Ticks < 50*60
  699. There should be no 2000 year real problem with the Amiga filesystem. Anyway,
  700. there is a page on 2YK problem with the Amiga at : http://www.amiga.com.
  701.  
  702. 4.2.1 How to find the first sector of a directory entry ?
  703.  
  704. Given the name of a file/directory/link you first have to compute its hash
  705. value with this algorithm :
  706.  
  707. * The hash function :
  708.  
  709. #include<ctype.h>
  710.  
  711. int HashName(char *name)
  712. {
  713. int hash;                               /* sizeof(int)>=2 */
  714. int i,l;
  715.  
  716. l=hash=strlen(name);
  717. for(i=0; i<l; i++) {
  718.         hash=hash*13;
  719.         hash=hash + toupper(name[i]);   /* not case sensitive */
  720.         hash=hash & 0x7ff;
  721.         }
  722. hash=hash % ((BSIZE/4)-56);             /* 0 < hash < 71
  723.                                          * in the case of 512 byte blocks */
  724.  
  725. return(hash);
  726. }
  727.  
  728. // this code only works with non international mode disks
  729. // see section 5.4
  730.  
  731. The hash value is then used to access HashTable ('ht' field in
  732. Rootblock/Directory block).
  733.  
  734. HashTable[ HashValue ] contains the number of the first block of your object
  735. (File header block, Directory block or Link block).
  736.  
  737. But different names can result in the same HashValue. If more then one name
  738. has the same HashValue, the other blocks (for files and directory only) are
  739. stored in a chained list. This linked list starts at the 'next_hash' field
  740. of the File header or Directory block.
  741.  
  742. For example : 'file_1a', 'file_24' and 'file_5u' have the same hash value.
  743.  
  744. Here follows the method to find the requested block :
  745.  
  746. HashValue = HashName( name );
  747. name=uppercase(name);
  748. nsector = Hashtable[ HashValue ];
  749. if (nsector != 0) {
  750.         sector=Load(nsector);           /* reads the 'nsector' sector */
  751.         sector.name = uppercase(sector.name);
  752.         /*
  753.          *  follows the 'same HashValue' chained list if needed
  754.          */
  755.         while ( sector.name != name and sector.Next_hash != 0) {
  756.                 sector = Load(nsector);
  757.                 sector.name = uppercase(sector.name);
  758.         }
  759.         if (sector.name != name)
  760.                 puts("File/Dir not found");
  761. }
  762. else
  763.         puts("File/Dir not found");
  764.  
  765. // this code only works with non international mode disks
  766. // see section 5.4
  767.  
  768. [Figure : HashTable and Directory content]
  769.  
  770. Filenames characters can be lowercase and uppercase, but as shown in the
  771. Hash function, are not case sensitive.
  772.  
  773. If, for a new entry, the value at hashTable[hashvalue] is different than 0,
  774. the new sector pointer will be stored in the last entry of the
  775. same-hashvalue-linked-list. It is necessary to check if the entry name
  776. already exists in this directory. In one word, in the same-hashValue list,
  777. the addition is made at the tail, not the head.
  778.  
  779. 4.2.2 How to list all the directory entries ?
  780.  
  781. Look through the whole HashTable and follow the same 'HashValue' linked
  782. lists if they exist.
  783.  
  784. 4.2.3 How to compute the checksum ?
  785.  
  786. #define Short(p) ((p)[0]<<8 | (p)[1])
  787. #define Long(p) (Short(p)<<16 | Short(p+2))
  788.  
  789. unsigned long newsum;
  790. unsigned char buf[BSIZE];       /* contains rootblock */
  791. int i;
  792.  
  793. memset(buf+20,0,4);             /* clear old checksum */
  794. newsum=0L;
  795. for(i=0; i<(BSIZE/4); i++)
  796.         newsum+=Long(buf+i*4);
  797. newsum=-newsum;                 /* negation */
  798.  
  799. This checksum algorithm works for most blocks type except for Bootblock.
  800.  
  801. The bitmap table ('bm_pages[]') stores one or several pointers to Bitmap
  802. blocks. The first pointer is at index 0.
  803.  
  804.                            -----------------------
  805.  
  806. 4.3 How are the free and used block lists managed?
  807.  
  808. Bitmap blocks contain information about free and allocated sectors. One bit
  809. is used per sector. If the bit is set, the sector is free, a cleared bit
  810. means an allocated sector.
  811.  
  812. Boot blocks allocation (2 for floppy, for hard disks the value can be found
  813. at DOSEnvVec->Bootblocks) is not stored in bitmap. Bitmap is stored in
  814. longs, the first sector of a long is the bit 0.
  815.  
  816. * Bitmap block (BSIZE bytes), often at rootblock+1
  817. -------------------------------------------------------------------------------
  818. 0/0x00  long    1               checksum        normal algorithm
  819. 4/0x04  long    (BSIZE/4)-1     map
  820. -------------------------------------------------------------------------------
  821.  
  822. Here follows for a DD disk the relationship between bitmap and sector number
  823. :
  824.  
  825. block #         long #  bit #
  826. -------------------------------
  827. 2               0       0
  828. 3               0       1
  829. 4               0       2
  830. ...
  831. 33              0       31
  832. 34              1       0
  833. 35              1       1
  834. ...
  835. 880             27      14
  836. 881             27      15
  837. ...
  838. 1759            54      28
  839. 1760            54      29
  840.  
  841. This map is 1758 bits long (1760-2) and is stored on 54 full filled long and
  842. the first 30th bits of the 55th long.
  843.  
  844. * What is the 'bm_ext' field in Rootblock ?
  845.  
  846. If 25 bitmap blocks (which pointers are stored on Rootblock) are not enough
  847. (for Hard Disks > ca. 50 Mbyte), extra needed bitmap blocks pointers are
  848. stored in bitmap extension blocks.
  849.  
  850. * Bitmap extension block (BSIZE bytes) (Hard disk only)
  851. -------------------------------------------------------------------------------
  852.        0/0x00   ulong   (BSIZE/4)-1     bitmap block pointers
  853. BSIZE- 4/0x04   ulong   1               next (0 for last)
  854. -------------------------------------------------------------------------------
  855.  
  856. The Bitmap extension linked list start at Rootblock with the 'bm_ext'.
  857.  
  858.                            -----------------------
  859.  
  860. 4.4 How are files stored ?
  861.  
  862. The first block of a file is the File header block, which contains
  863. information about the file (size, last access date, ...) and pointers to the
  864. first ((BSIZE/4)-56) Data blocks (i.e. for the often found case of BSIZE=512
  865. it contains 72 pointers).
  866. Data blocks store the actual file data.
  867.  
  868. If more than ((BSIZE/4)-56) Data blocks are needed to store a file, the
  869. other Data block pointers are stored in File extension blocks.
  870.  
  871. File extension blocks are organised in a linked list, which starts in File
  872. header block ('extension' field).
  873.  
  874. [Figure : Chained lists of the blocks which store files]
  875.  
  876. * File header block (BSIZE bytes)
  877. ------------------------------------------------------------------------------------------------
  878.         0/ 0x00 ulong   1       type            block primary type T_HEADER (==2)
  879.         4/ 0x04 ulong   1       header_key      self pointer (to this block)
  880.         8/ 0x08 ulong   1       high_seq        number of data block ptr stored here
  881.        12/ 0x0c ulong   1       data_size       unused (==0)
  882.        16/ 0x10 ulong   1       first_data      first data block ptr
  883.        20/ 0x14 ulong   1       chksum          same algorithm as rootblock
  884.        24/ 0x18 ulong   *       data_blocks[]   data blk ptr (first at BSIZE-204 )
  885.                                                 * = (BSIZE/4) - 56
  886. BSIZE-200/-0xc8 ulong   2       UNUSED          set to 0
  887. BSIZE-192/-0xc0 ulong   1       protect         protection flags (bit set)
  888.                                                 (default set to 0)
  889.                                         0       delete forbidden (D)
  890.                                         1       modification forbidden (E)
  891.                                         2       write/update forbidden (W)
  892.                                         3       read forbidden (R)
  893.                                         4       file is archived (A)
  894.                                         5       pure, can be made resident (P)
  895.                                         6       file is a script (S)
  896.                                         7       hidden file with DIR (H)
  897.                                      23-8       reserved
  898.                                     31-24       user
  899. BSIZE-188/-0xbc ulong   1       byte_size       file size in bytes
  900. BSIZE-184/-0xb8 char    1       comm_len        file comment length
  901. BSIZE-183/-0xb7 char    79      comment[]       comment (max. 79 chars permitted)
  902. BSIZE-104/-0x69 char    12      UNUSED          set to 0
  903. BSIZE- 92/-0x5c ulong   1       days            last access date (days since 1 jan 78)
  904. BSIZE- 88/-0x58 ulong   1       mins            last access time
  905. BSIZE- 84/-0x54 ulong   1       ticks           in 1/50s of a seconds
  906. BSIZE- 80/-0x50 char    1       name_len        filename length
  907. BSIZE- 79/-0x4f char    30      filename[]      filename (max. 30 chars permitted)
  908. BSIZE- 49/-0x31 char    1       UNUSED          set to 0
  909. BSIZE- 48/-0x30 ulong   1       UNUSED          set to 0
  910. BSIZE- 44/-0x2a ulong   1       real_entry      FFS : unused (== 0)
  911. BSIZE- 40/-0x28 ulong   1       next_link       FFS : hardlinks chained list (first=newest)
  912. BSIZE- 36/-0x24 ulong   5       UNUSED          set to 0
  913. BSIZE- 16/-0x10 ulong   1       hash_chain      next entry ptr with same hash
  914. BSIZE- 12/-0x0c ulong   1       parent          parent directory
  915. BSIZE-  8/-0x08 ulong   1       extension       pointer to 1st file extension block
  916. BSIZE-  4/-0x04 ulong   1       sec_type        secondary type : ST_FILE (== -3)
  917. ------------------------------------------------------------------------------------------------
  918.  
  919. As within volume names ':' and '/' are forbidden within file names.
  920.  
  921. The number of blocks used to store one file depends on the filesystem used,
  922. OFS or FFS. If one file has 7 datablocks, the first is at datablock[71-0],
  923. the last at datablocks[71-6], and highseq is equals to 7.
  924.  
  925. For the OFS there are two ways of reading the contents of a file. First by
  926. traversing the linked list of data blocks that is pointed to in first_data
  927. (offset 16) and then following the pointers in each file data block. The
  928. other way of accessing the file data is by using the data_blocks[] table and
  929. going backwards through the data blocks listed there and then the File
  930. extension blocks.
  931.  
  932. As the FFS doesn't contain extra information in the data blocks (no pointer
  933. list, no checksum) the only way of accessing the file contents is by going
  934. through the data_blocks[] table and the File extension blocks.
  935.  
  936. For an empty file, a Header file block is written, with 'byte_size' equal to
  937. 0, and no Data block pointers in 'data_blocks[]'.
  938.  
  939. * File extension block (BSIZE bytes) (first pointer in File header)
  940. ------------------------------------------------------------------------------------------------
  941.         0/ 0x00 ulong   1       type            primary type : T_LIST (== 16)
  942.         4/ 0x04 ulong   1       header_key      self pointer
  943.         8/ 0x08 ulong   1       high_seq        number of data blk ptr stored
  944.        12/ 0x0c ulong   1       UNUSED          unused (== 0)
  945.        16/ 0x10 ulong   1       UNUSED          unused (== 0)
  946.        20/ 0x14 ulong   1       chksum          rootblock algorithm
  947.        24/ 0x18 ulong   *       data_blocks[]   data blk ptr (first at BSIZE-204)
  948.                                                 * = (BSIZE/4) - 56
  949. BSIZE-200/-0xc8 ulong   46      info            unused (== 0)
  950. BSIZE- 16/-0x10 ulong   1       UNUSED          unused (== 0)
  951. BSIZE- 12/-0x0c ulong   1       parent          ptr to parent directory
  952. BSIZE-  8/-0x08 ulong   1       extension       next file header extension block,
  953.                                                 0 for the last
  954. BSIZE-  4/-0x04 ulong   1       sec_type        secondary type : ST_FILE (== -3)
  955. ------------------------------------------------------------------------------------------------
  956.  
  957. * Data blocks (BSIZE bytes) (first pointer in File header 'first_data' and
  958. 'data_blocks[((BSIZE/4)-57)]')
  959.  
  960. Old File System data block (BSIZE bytes)
  961. -------------------------------------------------------------------------------
  962. 0/0     ulong   1       type            primary type : T_DATA (== 8)
  963. 4/4     ulong   1       header_key      pointer to file header block
  964. 8/8     ulong   1       seq_num         file data block number (first is #1)
  965. 12/c    ulong   1       data_size       data size <= (BSIZE-24)
  966. 16/10   ulong   1       next_data       next data block ptr (0 for last)
  967. 20/14   ulong   1       chksum          rootblock algorithm
  968. 24/18   UCHAR   *       data[]          file data size <= (BSIZE-24)
  969. -------------------------------------------------------------------------------
  970.  
  971. In OFS, there is a second way to read a file : using the Data block chained
  972. list. The list starts in File header ('first_data') and goes on with
  973. 'next_data' in each Data block.
  974.  
  975. Fast File System (BSIZE bytes)
  976. -------------------------------------------------------------------------------
  977. 0/0     UCHAR   BSIZE   data[]          file data
  978. -------------------------------------------------------------------------------
  979.  
  980. In FFS, the only way to read or recover a file is to use data_blocks[] in
  981. the file header block and the File extension blocks. If a File header or
  982. File extension block is unreadable, there is no way to find the
  983. corresponding Data blocks.
  984.  
  985. The OFS is more robust than FFS, but slower and can store less data on disk.
  986. As you see, disk salvaging is easier with OFS.
  987.  
  988. When a file is deleted, only its File header block number is cleared from
  989. the Directory block (or from the same-hash-value list) and the bitmap is
  990. updated. File header block, Data blocks and File extension blocks are not
  991. cleared ! but the bitmap blocks are updated. Nevertheless, the undelete
  992. operation is easy .
  993.  
  994.                            -----------------------
  995.  
  996. 4.5 How are directories stored?
  997.  
  998. Directory blocks are very similar to Rootblock, except they don't need
  999. information about bitmap and disk, but have comments.
  1000.  
  1001. * User directory block (BSIZE bytes)
  1002. ------------------------------------------------------------------------------------------------
  1003.         0/ 0x00 ulong   1       type            block primary type = T_HEADER (value 2)
  1004.         4/ 0x04 ulong   1       header_key      self pointer
  1005.         8/ 0x08 ulong   3       UNUSED          unused (== 0)
  1006.        20/ 0x14 ulong   1       chksum          normal checksum algorithm
  1007.        24/ 0x18 ulong   *       ht[]            hash table (entry block number)
  1008.                                                 * = (BSIZE/4) - 56
  1009.                                                 for floppy disk: size= 72 longwords
  1010. BSIZE-200/-0xc8 ulong   2       UNUSED          unused (== 0)
  1011. BSIZE-192/-0xc0 ulong   1       protect         protection flags (bit set)
  1012.                                                 (default set to 0)
  1013.                                         0       delete forbidden (D)
  1014.                                         1       modification forbidden (E)
  1015.                                         2       write/update forbidden (W)
  1016.                                         3       read forbidden (R)
  1017.                                         4       directory is archived (A)
  1018.                                         5       pure, can be made resident (P)
  1019.                                         6       file is a script (S)
  1020.                                         7       hidden file with DIR (H)
  1021.                                      23-8       reserved
  1022.                                     31-24       user
  1023. BSIZE-188/-0xbc ulong   1       UNUSED          unused (== 0)
  1024. BSIZE-184/-0xb8 char    1       comm_len        directory comment length
  1025. BSIZE-183/-0xb7 char    79      comment[]       comment (max. 79 chars permitted)
  1026. BSIZE-104/-0x69 char    12      UNUSED          set to 0
  1027. BSIZE- 92/-0x5c ulong   1       days            last access date (days since 1 jan 78)
  1028. BSIZE- 88/-0x58 ulong   1       mins            last access time
  1029. BSIZE- 84/-0x54 ulong   1       ticks           in 1/50s of a seconds
  1030. BSIZE- 80/-0x50 char    1       name_len        directory name length
  1031. BSIZE- 79/-0x4f char    30      dirname[]       directory (max. 30 chars permitted)
  1032. BSIZE- 49/-0x31 char    1       UNUSED          set to 0
  1033. BSIZE- 48/-0x30 ulong   2       UNUSED          set to 0
  1034. BSIZE- 40/-0x28 ulong   1       next_link       FFS : hardlinks chained list (first=newest)
  1035. BSIZE- 36/-0x24 ulong   5       UNUSED          set to 0
  1036. BSIZE- 16/-0x10 ulong   1       hash_chain      next entry ptr with same hash
  1037. BSIZE- 12/-0x0c ulong   1       parent          parent directory
  1038. BSIZE-  8/-0x08 ulong   1       extension       FFS : first directory cache block
  1039. BSIZE-  4/-0x04 ulong   1       sec_type        secondary type : ST_USERDIR (== 2)
  1040. ------------------------------------------------------------------------------------------------
  1041.  
  1042. You can obtain directory listing exactly like with the root directory.
  1043.  
  1044.                            -----------------------
  1045.  
  1046. 4.6 How are links implemented in AmigaDOS ?
  1047.  
  1048. Only FFS handles links and directory caching.
  1049. Soft links are not supported by AmigaDOS 3.0. Linked files are seen as
  1050. directories...
  1051. However, some shells (like Csh 5.37) support them, so I'm supplying the
  1052. structure.
  1053.  
  1054. 4.6.1 Hard links
  1055.  
  1056. * Hard link (BSIZE bytes)
  1057. ------------------------------------------------------------------------------------------------
  1058.         0/ 0x00 ulong   1       type            block primary type = T_HEADER (value 2)
  1059.         4/ 0x04 ulong   1       header_key      self pointer
  1060.         8/ 0x08 ulong   3       UNUSED          unused (== 0)
  1061.        20/ 0x14 ulong   1       chksum          normal checksum algorithm
  1062.        24/ 0x18 ulong   *       UNUSED          set to 0
  1063.                                                 * = (BSIZE/4) - 54
  1064.                                                 for floppy disk: size= 74 longwords
  1065. BSIZE-192/-0xc0 ulong   1       protect         protection flags (bit set)
  1066.                                                 (default set to 0)
  1067.                                         0       delete forbidden (D)
  1068.                                         1       modification forbidden (E)
  1069.                                         2       write/update forbidden (W)
  1070.                                         3       read forbidden (R)
  1071.                                         4       directory is archived (A)
  1072.                                         5       pure, can be made resident (P)
  1073.                                         6       file is a script (S)
  1074.                                         7       hidden file with DIR (H)
  1075.                                      23-8       reserved
  1076.                                     31-24       user
  1077. BSIZE-188/-0xbc ulong   1       UNUSED          unused (== 0)
  1078. BSIZE-184/-0xb8 char    1       comm_len        comment length
  1079. BSIZE-183/-0xb7 char    79      comment[]       comment (max. 79 chars permitted)
  1080. BSIZE-104/-0x69 char    12      UNUSED          set to 0
  1081. BSIZE- 92/-0x5c ulong   1       days            last access date (days since 1 jan 78)
  1082. BSIZE- 88/-0x58 ulong   1       mins            last access time
  1083. BSIZE- 84/-0x54 ulong   1       ticks           in 1/50s of a seconds
  1084. BSIZE- 80/-0x50 char    1       name_len        hard link name length
  1085. BSIZE- 79/-0x4f char    30      hlname[]        hardlink name (max. 30 chars permitted)
  1086. BSIZE- 49/-0x31 char    1       UNUSED          set to 0
  1087. BSIZE- 48/-0x30 ulong   1       UNUSED          set to 0
  1088. BSIZE- 44/-0x2c ulong   1       real_entry      FFS : pointer to "real" file or directory
  1089. BSIZE- 40/-0x28 ulong   1       next_link       FFS : hardlinks chained list (first=newest)
  1090. BSIZE- 36/-0x24 ulong   5       UNUSED          set to 0
  1091. BSIZE- 16/-0x10 ulong   1       hash_chain      next entry ptr with same hash
  1092. BSIZE- 12/-0x0c ulong   1       parent          parent directory
  1093. BSIZE-  8/-0x08 ulong   1       UNUSED          set to 0
  1094. BSIZE-  4/-0x04 ulong   1       sec_type        secondary type : ST_LINKFILE = -4
  1095.                                                 ST_LINKDIR = 4
  1096. ------------------------------------------------------------------------------------------------
  1097.  
  1098. A 'real' entry is a file or directory entry, opposed to link entries.
  1099.  
  1100. A hard link can only be created on the same disk as the real entry disk.
  1101. Several links can be made on the same real entry. This is stored with a
  1102. chained list.
  1103. 'real entry' always contains the real entry block pointer.
  1104. 'next_link' stores the links linked list.
  1105.  
  1106. New entries are added at the head:
  1107.  
  1108. >ls
  1109.   ------rw-d     1912  15-May-96 22:28:08  real
  1110.  
  1111. Chained list state :
  1112.  
  1113. block# real     next    name
  1114. ----------------------------
  1115. 484     0       0       real
  1116.  
  1117. >ln real link1
  1118. >ls
  1119.   ------rw-d     1912  15-May-96 22:28:08  real
  1120.   -H----rw-d     1912  15-May-96 22:28:10  link1 -> Empty:real
  1121.  
  1122. block# real     next    name
  1123. ----------------------------
  1124. 484     0       104     real
  1125. 104     484     0       link1
  1126.  
  1127. >ln link1 link2
  1128. >ls
  1129.   ------rw-d     1912  15-May-96 22:28:08  real
  1130.   -H----rw-d     1912  15-May-96 22:28:10  link1 -> Empty:real
  1131.   -H----rw-d     1912  15-May-96 22:28:12  link2 -> Empty:real
  1132.  
  1133. block# real     next    name
  1134. ----------------------------
  1135. 484     0       107     real
  1136. 104     484     0       link1
  1137. 107     484     104     link2
  1138.  
  1139. The links are stored 'newest first', due to the adding at head.
  1140.  
  1141. real -> newest link -> ... -> oldest link -> 0
  1142.  
  1143. -> means "points to"
  1144.  
  1145. 4.6.2 Soft links
  1146.  
  1147. * Soft link (BSIZE bytes)
  1148. ------------------------------------------------------------------------------------------------
  1149.         0/ 0x00 ulong   1       type            block primary type = T_HEADER (value 2)
  1150.         4/ 0x04 ulong   1       header_key      self pointer
  1151.         8/ 0x08 ulong   3       UNUSED          unused (== 0)
  1152.        20/ 0x14 ulong   1       chksum          normal checksum algorithm
  1153.        24/ 0x18 ulong   *       symbolic_name   path name to referenced object, Cstring
  1154.                                                 * = ((BSIZE - 224) - 1)
  1155.                                                 for floppy disk: size= 288 - 1 chars
  1156. BSIZE-200/-0xc8 ulong   2       UNUSED          unused (== 0)
  1157. BSIZE-192/-0xc0 ulong   1       protect         protection flags (bit set)
  1158.                                                 (default set to 0)
  1159.                                         0       delete forbidden (D)
  1160.                                         1       modification forbidden (E)
  1161.                                         2       write/update forbidden (W)
  1162.                                         3       read forbidden (R)
  1163.                                         4       directory is archived (A)
  1164.                                         5       pure, can be made resident (P)
  1165.                                         6       file is a script (S)
  1166.                                         7       hidden file with DIR (H)
  1167.                                      23-8       reserved
  1168.                                     31-24       user
  1169. BSIZE-188/-0xbc ulong   1       UNUSED          unused (== 0)
  1170. BSIZE-184/-0xb8 char    1       comm_len        comment length
  1171. BSIZE-183/-0xb7 char    79      comment[]       comment (max. 79 chars permitted)
  1172. BSIZE-104/-0x69 char    12      UNUSED          set to 0
  1173. BSIZE- 92/-0x5c ulong   1       days            last access date (days since 1 jan 78)
  1174. BSIZE- 88/-0x58 ulong   1       mins            last access time
  1175. BSIZE- 84/-0x54 ulong   1       ticks           in 1/50s of a seconds
  1176. BSIZE- 80/-0x50 char    1       name_len        soft link name length
  1177. BSIZE- 79/-0x4f char    30      slname[]        softlink name (max. 30 chars permitted)
  1178. BSIZE- 49/-0x31 char    1       UNUSED          set to 0
  1179. BSIZE- 48/-0x30 ulong   8       UNUSED          set to 0
  1180. BSIZE- 16/-0x10 ulong   1       hash_chain      next entry ptr with same hash
  1181. BSIZE- 12/-0x0c ulong   1       parent          parent directory
  1182. BSIZE-  8/-0x08 ulong   1       UNUSED          set to 0
  1183. BSIZE-  4/-0x04 ulong   1       sec_type        secondary type : ST_SOFTLINK = 3
  1184. ------------------------------------------------------------------------------------------------
  1185.  
  1186.                            -----------------------
  1187.  
  1188. 4.7 How are the blocks associated with the directory cache mode ?
  1189.  
  1190. To speed up directory listing, Directory cache blocks have been created.
  1191. Directory cache blocks are also organised in chained lists.
  1192. The list starts at the directory block (root or normal directory) with the
  1193. 'extension' field.
  1194.  
  1195. * Directory cache block (BSIZE bytes)
  1196. -------------------------------------------------------------------------------
  1197. 0/0     ulong   1       type            DIRCACHE == 33 (0x21)
  1198. 4/4     ulong   1       header_key      self pointer
  1199. 8/8     ulong   1       parent          parent directory
  1200. 12/c    ulong   1       records_nb      directory entry records in this block
  1201. 16/10   ulong   1       next_dirc       dir cache chained list
  1202. 20/14   ulong   1       chksum          normal checksum
  1203. 24/18   UCHAR   *       records[]       entries list (size = BSIZE-24)
  1204. -------------------------------------------------------------------------------
  1205.  
  1206. The directory entries are stored this way :
  1207.  
  1208. * Directory cache block entry record (26 <= size (in bytes) <= 77)
  1209. -------------------------------------------------------------------------------
  1210. 0       ulong   1       header          entry block pointer
  1211.                                         (the link block for a link)
  1212. 4       ulong   1       size            file size (0 for a directory or a link)
  1213. 8       ulong   1       protect         protection flags (0 for a link ?)
  1214. 12      ulong   1       UNUSED          ( == 0 )
  1215. 16      short   1       days            date (always filled)
  1216. 18      short   1       mins            time (always filled)
  1217. 20      short   1       ticks
  1218. 22      char    1       type            secondary type
  1219. 23      char    1       name_len        1 <= len <= 30 (nl)
  1220. 24      char    ?       name            name
  1221. 24+nl   char    1       comm_len        0 <= len <= 22 (cl)
  1222. 25+nl   char    ?       comment         comment
  1223. 25+nl+cl char   1       OPTIONAL padding byte(680x0 longs must be word aligned)
  1224. -------------------------------------------------------------------------------
  1225.  
  1226.   ------------------------------------------------------------------------
  1227.  
  1228. 5. How does a blank disk look like ?
  1229.  
  1230. A minimal blank disk has a Bootblock, a Rootblock and a Bitmap block.
  1231.  
  1232. 5.1 a Minimal blank floppy disk
  1233.  
  1234. * The Bootblock (0 and 1)
  1235.  
  1236. 0       char    4       ID              'D''O''S' + flags
  1237. 4       long    1023    full of zeros
  1238.  
  1239. * The Rootblock (880)
  1240.  
  1241. 0       long    1       type            2
  1242. 12/c    long    1       ht_size         0x48
  1243. 20/14   long    1       checksum        computed
  1244. 312/138 long    1       bm_flag         -1 (valid bitmap)
  1245. 316/13c long    1       bm_pages[0]     bitmap sector #
  1246. 420/1a4 long    1       last access date
  1247. 424/1a8 long    1       last access time
  1248. 428/1ac long    1       last access time
  1249. 432/1b0 char    1       disk_name size
  1250. 433/1b1 char    ?       disk_name
  1251. 472/1d8 long    1       last access date
  1252. 476/1dc long    1       last access time
  1253. 480/1e0 long    1       last access time
  1254. 484/1e4 long    1       creation date
  1255. 488/1e8 long    1       creation time
  1256. 492/1ec long    1       creation time
  1257. 504/1f8 long    1       FFS : first dir cache sector  or 0
  1258. 508/1fc long    1       sub_type        1
  1259.  
  1260. No specified fields are set to 0.
  1261.  
  1262. * The Bitmap block (here 881) for a DD disk
  1263.  
  1264. 0       long    1       checksum
  1265. 4       long    27      free sectors    0xffffffff
  1266. 112/70  long    1       root+bitmap     0xffff3fff
  1267. 116/74  long    27      free sectors    0xffffffff
  1268. 120/78  long    72      unused          !=0
  1269.  
  1270.                            -----------------------
  1271.  
  1272. 5.2 A 'Bootable' floppy disk
  1273.  
  1274. * The Bootblock becomes :
  1275.  
  1276. 0/0x00  long    1       ID              'D''O''S' + flags
  1277. 4/0x04  long    1       checksum        computed
  1278. 8/0x08  long    1       rootblock ?     880
  1279. 12/0x0c byte    81      bootcode        AmigaDOS 3.0 version
  1280.  
  1281.         values                  disassembled
  1282.         --------------+---------------------
  1283.         43FA003E                lea     exp(pc),a1      ;Lib name
  1284.         7025                    moveq   #37,d0          ;Lib version
  1285.         4EAEFDD8                jsr     -552(a6)        ;OpenLibrary()
  1286.         4A80                    tst.l   d0              ;error == 0
  1287.         670C                    beq.b   error1
  1288.         2240                    move.l  d0,a1           ;lib pointer
  1289.         08E90006 0022           bset    #6,34(a1)       ;(*)
  1290.         4EAEFE62                jsr     -414(a6)        ;CloseLibrary()
  1291.         43FA0018        error1: lea     dos(PC),a1      ;name
  1292.         4EAEFFA0                jsr     -96(a6)         ;FindResident()
  1293.         4A80                    tst.l   d0
  1294.         670A                    beq.b   error2          ;not found
  1295.         2040                    move.l  d0,a0
  1296.         20680016                move.l  22(a0),a0       ;DosInit sub
  1297.         7000                    moveq   #0,d0
  1298.         4E75                    rts
  1299.         70FF            error2: moveq   #-1,d0
  1300.         4E75                    rts
  1301.         646F732E 6C696272 617279
  1302.                         dos:    "dos.library"
  1303.         00                                              ;padding byte
  1304.         65787061 6E73696F 6E2E6C69 62726172 79
  1305.                         exp:    "expansion.library"
  1306.  
  1307. 93/0x5d byte    931     full of zeros
  1308.  
  1309. (*) from Thomas Kessler (tkessler@ra.abo.fi), may 1997 :
  1310. This bit tells the shell (which opens its shell-window when booting the
  1311. startup-sequence) not to open window unless needed, so a black screen stays
  1312. there during boot instead of an empty shell-windows (it's a os2.x feature).
  1313.  
  1314.                            -----------------------
  1315.  
  1316. 5.3 A Directory cache mode floppy disk
  1317.  
  1318. * A directory cache block (here 882)
  1319.  
  1320. 0       long    1       type            0x21
  1321. 4       long    1       self pointer    882
  1322. 8       long    1       cached dir      880 (root)
  1323. 12/c    long    1       entries number  0
  1324. 16/10   long    1       next dir cache  0 (last)
  1325. 20/14   long    1       checksum        computed
  1326. 24      long    122     full of zeros
  1327.  
  1328.                            -----------------------
  1329.  
  1330. 5.4 International Mode
  1331.  
  1332. The toupper() function in the HashName() function (3.2.1 paragraph) is
  1333. replaced by the following function with the aim of better handling
  1334. international characters :
  1335.  
  1336. int intl_toupper(int c)
  1337. {
  1338.    return (c>='a' && c<='z') || (c>=224 && c<=254 && c!=247) ? c - ('a'-'A') : c ;
  1339. }
  1340.  
  1341. In the Amiga ASCII table, the international character codes are between 192
  1342. and 254. Uppercase caracters are between 192 and 222, the lowercase versions
  1343. of them are between 224 and 254. The only exception are the codes 215 and
  1344. 247, which are respectively the multiply sign and the divide sign.
  1345.  
  1346. The Amiga character set is the same as ISO 8879 Latin-1 character set, used
  1347. in HTML standard. This character set is described here : http://www.w3c.org/
  1348.  
  1349.   ------------------------------------------------------------------------
  1350.  
  1351. 6. The structure of a hard disk
  1352.  
  1353. The following structures is mainly extracted from the 'devices/hardblocks.h'
  1354. and 'dos/filehandler.h' files delivered in Commodore developer kits.
  1355.  
  1356. The hard disk specific structures mainly store the drive geometry, the
  1357. written partitions sizes and the filesystem bootcode.
  1358.  
  1359. The five kind of blocks are in a reserved area, at the beginning of the
  1360. surface. The first of them, Rigid Disk block (RDSK), must be found within
  1361. the first 16 blocks of BSIZE lenght. But it can be written inside the data
  1362. area, which is dangerous.
  1363.  
  1364. 6.1 What is the Rigid Disk Block ?
  1365.  
  1366. * Rigid Disk block (256 bytes) must exist within the first 16 blocks
  1367. -------------------------------------------------------------------------------
  1368. 0/0     char    4       id              'RDSK'
  1369. 4/4     ulong   1       size in longs   == 64
  1370. 8/8     long    1       checksum        classic Rootblock algorithm
  1371. 12/c    ulong   1       hostID          SCSI Target ID of host
  1372.                                         (== 7 for IDE and ZIP disks)
  1373. 16/10   ulong   1       block size      typically 512 bytes, but can
  1374.                                         be other powers of 2
  1375. 20/14   ulong   1       flags           typically 0x17
  1376.                                 Bits    If set means :
  1377.                                 0       No disks exists to be configured
  1378.                                         after this one on this controller
  1379.                                 1       No LUNs exists to be configured greater
  1380.                                         than this one at this SCSI Target ID
  1381.                                 2       No target IDs exists to be configured
  1382.                                         greater than this one on this SCSI bus
  1383.                                 3       Don't bother trying to perform
  1384.                                         reselection when talking to this drive
  1385.                                 4       Disk indentification valid
  1386.                                 5       Controller indentification valid
  1387.                                 6       Drive supports SCSI synchronous mode
  1388.                                         (can be dangerous if it doesn't)
  1389. 24/18   ulong   1       Bad blockList   block pointer (-1 means last block)
  1390. 28/1c   ulong   1       PartitionList   block pointer (-1 means last)
  1391. 32/20   ulong   1       FileSysHdrList  block pointer (-1 means last)
  1392. 36/24   ulong   1       DriveInit code  optional drive-specific init code
  1393.                                         DriveInit(lun,rdb,ior) :
  1394.                                         "C" stack and d0/a0/a1
  1395. 40/28   ulong   6       RESERVED        == -1
  1396.  
  1397.         Physical drive caracteristics
  1398. 64/40   ulong   1       cylinders       number of drive cylinder
  1399. 68/44   ulong   1       sectors         sectors per track
  1400. 72/48   ulong   1       heads           number of drive heads
  1401. 76/4c   ulong   1       interleave
  1402. 80/50   ulong   1       parking zone    landing zone cylinders
  1403.                                         soon after the last cylinder
  1404. 84/54   ulong   3       RESERVED        == 0
  1405. 96/60   ulong   1       WritePreComp    starting cyl : write precompensation
  1406. 100/64  ulong   1       ReducedWrite    starting cyl : reduced write current
  1407. 104/68  ulong   1       StepRate        drive step rate
  1408. 108/6c  ulong   5       RESERVED        == 0
  1409.  
  1410.         Logical drive caracteristics
  1411. 128/80  ulong   1       RDB_BlockLo     low block of range reserved for hardblk
  1412. 132/84  ulong   1       RDB_BlockHi     high block of range for this hardblocks
  1413. 136/88  ulong   1       LoCylinder      low cylinder of partitionable disk area
  1414. 140/8c  ulong   1       HiCylinder      high cylinder of partitionable data area
  1415. 144/90  ulong   1       CylBlocks       number of blocks available per cylinder
  1416. 148/94  ulong   1       AutoParkSeconds zero for no autopark
  1417. 152/98  ulong   1       HighRSDKBlock   highest block used by RDSK
  1418.                                         (not including replacement bad blocks)
  1419. 156/9c  ulong   1       RESERVED        == 0
  1420.  
  1421.         Drive identification
  1422. 160/a0  char    8       DiskVendor      ie 'IOMEGA'
  1423. 168/a8  char    16      DiskProduct     ie 'ZIP 100'
  1424. 184/b8  char    4       DiskRevision    ie 'R.41'
  1425. 188/bc  char    8       ControllerVendor
  1426. 196/c4  char    16      ControllerProduct
  1427. 212/d4  char    4       ControllerRevision
  1428. 216/d8  ulong   10      RESERVED        == 0
  1429. 256/100
  1430. -------------------------------------------------------------------------------
  1431.  
  1432. * How to find the physical geometry of the disk ?
  1433.  
  1434. A hard disk is made of several physical disks. They have one head for each
  1435. writable side. Each physical disk consists of several tracks, which consist
  1436. of several sectors. One cylinder is the set of the tracks which have the
  1437. same number on each disk.
  1438.  
  1439. The total size of the hard disk is expressed in cylinders ('cylinders').
  1440. The size of a cylinder is :
  1441. the number of heads per cylinder ('heads')
  1442. x the number of sectors per track ('sectors')
  1443. x the size of a block ('block size').
  1444.  
  1445. The 'CylBlocks' field equals to 'heads' x 'sectors'.
  1446.  
  1447. The reserved area is often the 2 first cylinders, between the 'RDB_BlockLo'
  1448. block and the 'RDB_BlockHi' block, included. The partitionable area, starts
  1449. at the 'LoCylinder' cylinder until the 'HiCylinder' cylinder, included.
  1450.  
  1451. The really last used sector in the reserved area is the sector numbered
  1452. 'HighRSDKBlock', the first is numbered 0. The SCSI 'hostID' is set to the id
  1453. of the SCSI host controller, which is typically 7. Real SCSI drives ID must
  1454. be between 0 and 6.
  1455.  
  1456. The RDSK block is the "root" of the reserved area. It also contains the
  1457. first blocks of three linked lists : one the bad blocks replacement, one for
  1458. the partition definitions and one last for the filesystem information.
  1459.  
  1460. Some geometry examples :
  1461.  
  1462.    * a Zip disk : 2891 cylinders, 1 head, 68 sectors,
  1463.    * my 80Mb Seagate IDE harddisk : 980 cylinders, 10 heads, 17 sectors.
  1464.    * a 500 Mbyte Fujitsu 2624SA: 1472 cylinders, 11 heads, 63 sectors
  1465.    * a 50 Mbyte Quantum LPS52: 2085 cylinders, 1 head, 49 sectors
  1466.  
  1467.                            -----------------------
  1468.  
  1469. 6.2 How are bad blocks managed ?
  1470.  
  1471. * Bad Block block (BSIZE bytes) first in RDSK 'BadBlockList' field
  1472. -------------------------------------------------------------------------------
  1473. 0/0     ulong   1       id              'BADB'
  1474. 4/4     ulong   1       size in longs   == 128 for BSIZE = 512
  1475. 8/8     long    1       checksum
  1476. 12/c    ulong   1       HostID          == 7 ?
  1477. 16/10   ulong   1       next            next BadBlock block
  1478. 20/14   ulong   1       RESERVED
  1479. 24/18           *       BlockPairs[]    bad block entries table
  1480.                                         * size = ((BSIZE/4)-6)/2
  1481.                                         (for BSIZE=512 = 61*8 byte entries)
  1482. -------------------------------------------------------------------------------
  1483.  
  1484. * Bad Block entry (8 bytes) stored in BadBlock 'BlockPairs[]' field
  1485. -------------------------------------------------------------------------------
  1486. 0/0     ulong   1       BadBlock        block number of bad block
  1487. 4/4     ulong   1       GoodBlock       block number of replacement block
  1488. -------------------------------------------------------------------------------
  1489.  
  1490.                            -----------------------
  1491.  
  1492. 6.3 How are partitions stored?
  1493.  
  1494. * Partition block (256 bytes) first in RDSK 'PartitionList' field
  1495. -------------------------------------------------------------------------------
  1496. 0/0     char    4       ID              'PART'
  1497. 4/4     ulong   1       size in long    of checksummed structure (== 64)
  1498. 8/8     ulong   1       checksum        classic algorithm
  1499. 12/c    ulong   1       hostID          SCSI Target ID of host (== 7)
  1500. 16/10   ulong   1       next            block number of the next Partitionblock
  1501. 20/14   ulong   1       Flags
  1502.                                 Bits    If set means
  1503.                                 0       This partition is bootable
  1504.                                 1       No automount
  1505. 24/18   ulong   2       RESERVED
  1506. 32/20   ulong   1       DevFlags        preferred flags for OpenDevice
  1507. 36/24   char    1       DriveName len   length of Drive name (e.g. 3)
  1508. 37/25   char    31      DriveName       e.g. 'DH0'
  1509. 68/44   ulong   15      RESERVED
  1510.  
  1511.         DOS Environment vector (DOSEnvVec) (often defined in MountLists)
  1512. 128/80  ulong   1       size of vector  == 16 (longs), 11 is the minimal value
  1513. 132/84  ulong   1       SizeBlock       size of the blocks in longs ==
  1514.                                         128 for BSIZE = 512
  1515. 136/88  ulong   1       SecOrg          == 0
  1516. 140/8c  ulong   1       Surfaces        number of heads (surfaces) of drive
  1517. 144/90  ulong   1       sectors/block   sectors per block == 1
  1518. 148/94  ulong   1       blocks/track    blocks per track
  1519. 152/98  ulong   1       Reserved        DOS reserved blocks at start of partition
  1520.                                         usually = 2 (minimum 1)
  1521. 156/9c  ulong   1       PreAlloc        DOS reserved blocks at end of partition
  1522.                                         (no impact on Root block allocation)
  1523.                                         normally set to == 0
  1524. 160/a0  ulong   1       Interleave      == 0
  1525. 164/a4  ulong   1       LowCyl          first cylinder of a partition (inclusive)
  1526. 168/a8  ulong   1       HighCyl         last cylinder of a partition (inclusive)
  1527. 172/ac  ulong   1       NumBuffer       often 30 (used for buffering)
  1528. 176/b0  ulong   1       BufMemType      type of mem to allocate for buffers ==0
  1529. 180/b4  ulong   1       MaxTransfer     max number of type to transfer at a type
  1530.                                         often 0x7fff ffff
  1531. 184/b8  ulong   1       Mask            Address mask to block out certain memory
  1532.                                         often 0xffff fffe
  1533. 188/bc  ulong   1       BootPri         boot priority for autoboot
  1534. 192/c0  char    4       DosType         'DOS' and the FFS/OFS flag only
  1535.                                         also 'UNI'\0 = AT&T SysV filesystem
  1536.                                         'UNI'\1 = UNIX boot filesystem
  1537.                                         'UNI'\2 = BSD filesystem for SysV
  1538.                                         'resv' = reserved (swap space)
  1539. 196/c4  ulong   1       Baud            Define default baud rate for Commodore's
  1540.                                         SER and AUX handlers, originally
  1541.                                         used with the A2232 multiserial board
  1542. 200/c8  ulong   1       Control         used by Commodore's AUX handler
  1543. 204/cc  ulong   1       Bootblocks      Kickstart 2.0: number of blocks
  1544.                                         containing boot code to be
  1545.                                         loaded at startup
  1546. 208/d0  ulong   12      RESERVED
  1547. -------------------------------------------------------------------------------
  1548.  
  1549. There exists one 'PART' block per partition.
  1550.  
  1551. The block pointers in the reserved area are relative to the beginning of the
  1552. media. The block pointers in a partition are relative to the first block of
  1553. the partition.
  1554.  
  1555. The Rootblock of a partition is normally located in the middle of an
  1556. AmigaDOS filesystem. Please see 4.2 What is a Rootblock? for the exact
  1557. calculation of it's location.
  1558.  
  1559. The first two blocks of a partition contain a Bootblock. You have to use it
  1560. to determine the correct file system, and if the international or dircache
  1561. modes are used. Don't rely only on the PART and FSHD 'DosType' field.
  1562.  
  1563.                            -----------------------
  1564.  
  1565. 6.4 What are FSHD blocks ?
  1566.  
  1567. * Filesystem header block (256 bytes) first in RSDK 'FileSysHeaderList'
  1568. -------------------------------------------------------------------------------
  1569. 0/0     char    4       id              'FSHD'
  1570. 4/4     ulong   1       size in longs   == 64
  1571. 8/8     long    1       checksum        classic algorithm
  1572. 12/c    ulong   1       hostID          SCSI Target ID of host (often 7)
  1573. 16/10   ulong   1       next            block number of next FileSysHeaderBlock
  1574. 20/14   ulong   1       flags
  1575. 24/18   ulong   2       RESERVED
  1576. 32/20   char    4       DosType         'DOS' and OFS/FFS DIRCACHE INTL bits
  1577. 36/24   ulong   1       Version         filesystem version 0x0027001b == 39.27
  1578. 40/28   ulong   1       PatchFlags      bits set for those of the following
  1579.                                         that need to be substituted into a
  1580.                                         standard device node for this
  1581.                                         filesystem : e.g. 0x180 to substitute
  1582.                                         SegList and GlobalVec
  1583.         Device node
  1584. 44/2c   ulong   1       Type            device node type == 0
  1585. 48/30   ulong   1       Task            standard DOS "task" field == 0
  1586. 52/34   ulong   1       Lock            not used == 0
  1587. 56/38   ulong   1       Handler         filename to loadseg == 0
  1588. 60/3c   ulong   1       StackSize       stacksize to use when starting task ==0
  1589. 64/40   ulong   1       Priority        task priority when starting task == 0
  1590. 68/44   ulong   1       Startup         startup msg == 0
  1591. 72/48   ulong   1       SegListBlock    first of linked list of LoadSegBlocks :
  1592.                                         note that this entry requires some
  1593.                                         processing before substitution
  1594. 76/4c   ulong   1       GlobalVec       BCPL global vector when starting task =-1
  1595. 80/50   ulong   23      RESERVED        by PatchFlags
  1596. 172/ac  ulong   21      RESERVED
  1597. -------------------------------------------------------------------------------
  1598.  
  1599. This block contains information on how to lauch the task which will manage
  1600. the filesystem. You don't need it to reach partitions.
  1601.                            -----------------------
  1602.  
  1603. 6.5 What are LSEG blocks ?
  1604.  
  1605. * LoadSeg block (BSIZE bytes) first in FileSysHeaderBlock 'SegListBlocks' field
  1606. -------------------------------------------------------------------------------
  1607. 0/0     char    4       id              'LSEG'
  1608. 4/4     long    *       size in longs   size of this checksummed structure
  1609.                                         * size = BSIZE/4
  1610. 8/8     long    1       checksum        classic checksum
  1611. 12/c    long    1       hostID          SCSI Target ID of host (often 7)
  1612. 16/10   long    1       next            block number of the next LoadSegBlock
  1613.                                         (-1 for the last)
  1614. 20/14   uchar   *       LoadData[]      code stored like an executable, with
  1615.                                         relocation hunks
  1616.                                         * size = ((BSIZE/4) - 5)
  1617. -------------------------------------------------------------------------------
  1618.  
  1619. This block contains the code of the filesystem. It isn't needed to reach
  1620. partitions.
  1621.   ------------------------------------------------------------------------
  1622.  
  1623. 7. The Hard file : a big floppy dump file
  1624.  
  1625. A hardfile is a file which contains an Amiga volume.
  1626.  
  1627. It is created with WinUAE (http://www.codepoet.com/UAE/), and not the Amiga
  1628. and the AmigaDOS. WinUAE is able to produce an empty file with random
  1629. contents of a choosen size, often several megabytes long.
  1630. Under WinUAE, a AmigaDOS device appears, associated with the uaehf.device
  1631. (UAE hardfile). You have to format it with the Workbench, and you obtain an
  1632. 'hardfile'. This volume is then usable inside the emulator by AmigaDOS (it
  1633. should also be mountable under Linux with the AFFS filesystem).
  1634.  
  1635. An hardfile is like a floppy disk dump, but bigger : it has a bootblock, a
  1636. rootblock, a bitmap and perhaps dircache blocks.
  1637. The first three bytes of a hardfile is then 'D' 'O' 'S'.
  1638.  
  1639.   ------------------------------------------------------------------------
  1640.  
  1641. 8. Advanced information
  1642.  
  1643. Bitmap related
  1644.  
  1645. * Bitmap allocation starts at root block, upto highest block. The next
  1646. allocated blocks are located just after boot blocks and finally the last
  1647. allocated block is the sector before root block.
  1648.  
  1649. root -> max -> boot+1 -> root-1
  1650.  
  1651. -> means "followed on disk by"
  1652.  
  1653. If you free some blocks by deleting a file, for example, the first next used
  1654. block will be the first free block encountered starting from the Rootblock.
  1655. The just freed blocks will be reused. It means that when you delete a file
  1656. and you want to recover it, don't write anything else on the disk.
  1657. This strategy must have been chosen to minimize fragmentation
  1658.  
  1659. Files related
  1660.  
  1661. * The order in which data and file extension blocks for a given file are
  1662. written on disk differs with OFS and FFS.
  1663.  
  1664.    * OFS & FFS : All the data blocks of the file header block are written
  1665.      first.
  1666.    * FFS : Then follow all the file extension blocks of the file, then all
  1667.      the remaining data blocks are written.
  1668.      OFS : Each file extension block is followed by the related data blocks.
  1669.      So the last extension block is followed by the remaining data blocks.
  1670.  
  1671. OFS:
  1672. header -> data blocks -> ext. block -> data blocks -> ext. block -> data
  1673. blocks
  1674.  
  1675. FFS:
  1676. header -> data blocks -> all ext. block -> all remaining data blocks
  1677.  
  1678. -> means "followed on disk by"
  1679.  
  1680. This difference is probably the main reason why FFS is faster then OFS.
  1681.  
  1682. Compare the ADF logical blocks
  1683.  
  1684.                             root  dir   fileh   hlink   slink   fext    data    dirc
  1685. ----------------------------------------------------------------------------------------
  1686.         0/ 0x00 1st_type    2     2     2       2       2       16      8       33
  1687.         4/ 0x04 header_key  /     x     x       x       x       x       x       x
  1688.         8/ 0x08             /     /     nb_blo  /       /       nb_blo  block#  PARENT
  1689.        12/ 0x0c table_size  72    /     /       /       /       /       nb_data nb_rec
  1690.        16/ 0x10 list        /     /     data#1  /       /       /       next    next
  1691.        20/ 0x14 chksum      x     x     x       x       x       x       x       x
  1692.        24/ 0x18 table       ht    ht    blocks  /       /       blocks  data    records
  1693.     ...
  1694. BSIZE-184/-0xb8 comment_len /     x     x       /       /       /       /       /
  1695. BSIZE-183/-0xb7 comment     /     x     x       /       /       /       /       /
  1696.     ...
  1697. BSIZE- 92/-0x5c days        x     x     x       x       x       /       /       /
  1698. BSIZE- 88/-0x58 mins        x     x     x       x       x       /       /       /
  1699. BSIZE- 84/-0x54 ticks       x     x     x       x       x       /       /       /
  1700. BSIZE- 80/-0x50 name_len    x     x     x       x       x       /       /       /
  1701. BSIZE- 79/-0x4f name        x     x     x       x       x       /       /       /
  1702.     ...
  1703. BSIZE- 16/-0x10 hash_chain  /     x     x                       /       /       /
  1704. BSIZE- 12/-0x0c parent      /     x     x       x       x       fhdr    /       /
  1705. BSIZE-  8/-0x08 extension   cache cache fext    /       /       next    /       /
  1706. BSIZE-  4/-0x04 2nd_type    1     2     -3      -4/4    3       -3      /       /
  1707. ----------------------------------------------------------------------------------------
  1708.  
  1709. type of blocks :
  1710.  root=rootblock,  dir=directory,  fileh=file header,  fext=file extension,
  1711.  hlink=hard link,  slink=soft link,  dirc=directory cache,  data=OFS data.
  1712.  
  1713. special values :
  1714.  /=unused
  1715.  x=used
  1716.  next=next block of same type
  1717.  
  1718. How to rename an entry ?
  1719.  
  1720.   1. Compute the new hashvalue
  1721.   2. Move the first sector pointer from the old hashvalue index to the new
  1722.      one
  1723.   3. Change the name in the directory or file header block
  1724.  
  1725.   ------------------------------------------------------------------------
  1726.  
  1727. 9. References and links
  1728.  
  1729. * ASM Sources:
  1730.  
  1731.    * Scoopex and Crionics disassembled demo hardloaders
  1732.    * 'the floppy disk book' copier source file, DATA BECKER books, 1988
  1733.  
  1734. * On-Line material :
  1735.  
  1736.    * Very good 'ded.doc' file including Hard Disk information :
  1737.      ftp://ftp.funet.fi/pub/amiga/utilities/disk/Ded-1.11.lha
  1738.    * A clean track-loader which doesn't use AmigaDOS (by Patrik Lundquist) :
  1739.      ftp://ftp.wustl.edu/pub/aminet/dev/asm/t-loader.lha
  1740.    * A replacement for 'trackdisk.device' :
  1741.      ftp://ftp.wustl.edu/pub/aminet/disk/misc/hackdisk202.lha
  1742.    * 'amigadisk_hardware.doc' (by Dave Edwards, Mark Meany, ... of ACC) :
  1743.      http://home.sol.no/svjohan/assem/refs/diskHW.lha
  1744.  
  1745. * Books :
  1746.  
  1747.    * The Amiga Guru Book, Ralph Babel, 1993
  1748.    * Rom Kernel Reference Manual : Hardware, pages 235-244, Addison Wesley
  1749.    * La Bible de l'Amiga, Dittrich/Gelfand/Schemmel, Data Becker, 1988.
  1750.  
  1751. The AmigaDOS reference manual probably contains a lot of information about
  1752. Amiga file systems, but i don't own it (Addison Wesley). The most detailed
  1753. information about AmigaDOS can be found in Ralph Babel's "Amiga Guru Book".
  1754.   ------------------------------------------------------------------------
  1755.  
  1756. 10. C routines : the ADF library
  1757.  
  1758. The ADFlib is a portable C library designed to manage Amiga formatted
  1759. devices like harddisks and ZIP disks, or dump files of this kind of media
  1760. via the .ADF format.
  1761.  
  1762. The API permits you to :
  1763.  
  1764.    * mount/unmount a device (real one or a dump file),
  1765.    * mount/unmount a volume (partition),
  1766.    * create/open/close/delete/move a file,
  1767.    * read/write bytes from/to a file,
  1768.    * create/delete a directory,
  1769.    * get directory contents, change current directory, get parent directory.
  1770.  
  1771. A callbacks system makes it easy to write a real device driver for any
  1772. platform. The ADFOpus ( http://www.chromerhino.demon.co.uk/adfopus)
  1773. application (a useful Windows Explorer like for ADF files and devices),
  1774. written by Dan Sutherland is able to access from Win95/98/NT an 2.5 inches
  1775. harddisk formatted under AmigaDOS.
  1776.  
  1777. See the 1.2 section to see how to obtain the package.
  1778.   ------------------------------------------------------------------------
  1779.  
  1780. 11. Other Amiga FileSystems
  1781.  
  1782.    * ADFOpus : an 'ADF files explorer', by Dan Sutherland (
  1783.      http://www.chromerhino.demon.co.uk/adfopus/)
  1784.    * An Amiga filesystem for Linux 0.99pl2 by Ray Burr (read only, hard
  1785.      disk): ftp://tsx-11.mit.edu/pub/linux/patches/amigaffs.tar.Z
  1786.    * The AFFS filesystem inside the Linux kernel distribution by
  1787.      Hans-Joachim "JBHR" Widmaier (RDSK, links and international mode
  1788.      supported, dircache disks read-only): ftp://ftp.us.kernel.org in
  1789.      /usr/src/linux/fs/affs/
  1790.    * An .ADF manipulation package for DOS/Windows, "ADF-suite" (GUI,
  1791.      Shareware, no sources included):
  1792.      http://www.geocities.com/SiliconValley/Lakes/7094/index.html
  1793.  
  1794.   ------------------------------------------------------------------------
  1795. The .ADF format FAQ ends here !
  1796.